<template>
  <div>
    <el-button type="success" @click="toAddOrEdit()">新增或编辑</el-button>
    <el-dialog v-dialogDrag ref="dialog_isAdd" :title="addOrEdit" :visible.sync="isAdd" width="40%">
      <el-form :model="theAdd" :rules="rules" ref="ruleForm" label-width="100px">
        <el-form-item label="编码" prop="goods_number">
          <el-input v-model="theAdd.goods_number" placeholder="请输入编码" clearable></el-input>
        </el-form-item>
        <el-form-item label="供应商" prop="supplier_id">
          <el-select v-model="theAdd.supplier_id" placeholder="请选择供应商">
            <el-option
              v-for="item in allSupplier"
              :key="item.supplier_id"
              :label="item.supplier_name+'-'+item.supplier_phone"
              :value="item.supplier_id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="success" @click="doAdd('ruleForm')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      allSupplier: [
        //下拉选择数据
        {
          supplier_id: 1,
          supplier_name: "众信慧德",
          supplier_phone: "15195821268",
          supplier_address: "惠达路9号",
          supplier_contact_ren: "李达",
          remark: null,
          supplier_yuliu1: "",
          supplier_yuliu2: null
        },
        {
          supplier_id: 2,
          supplier_name: "众信",
          supplier_phone: "123456789111",
          supplier_address: "惠达路",
          supplier_contact_ren: "林冲",
          remark: "测试",
          supplier_yuliu1: "",
          supplier_yuliu2: null
        }
      ],
      isAdd: false, //是否新增
      addOrEdit: "新增", //新增或编辑（弹窗标题）
      theAdd: { goods_number: "" }, //新增和编辑表单
      rules: {
        //表单验证
        goods_number: [
          { required: true, message: "请输入编码", trigger: "blur" },
          { min: 3, max: 25, message: "长度在 3 到 25 个字符", trigger: "blur" }
        ]
      }
    };
  },
  components: {},
  methods: {
    toAddOrEdit() {
      this.isAdd = true;
    },
    doAdd(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert("valid");
        } else {
          alert("error");
          return false;
        }
      });
    }
  },
  created() {},
  mounted() {}
};
</script>
<style scoped>
</style>


